package com.zoe.thread.th16_deathLock死锁;

import java.util.concurrent.TimeUnit;

/**
 * @Author Zoe
 * @Date: 2021/05/07
 * @Description
 */
class Death {
    public String a;
    private String b;
    public void runs(String str, String str1) {
        synchronized (str) {
            System.out.println("obj");
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (str1) {
                System.out.println("obj1");
            }
        }
    }
}

public class SyncDeathLockDemo {
    public static void main(String[] args) {
        Death death = new Death();

        String str = "a";
        String str1 = "b";
        new Thread(() -> {
            death.runs(str, str1);
        }, "A").start();

        new Thread(() -> {
            death.runs(str1, str);
        }, "B").start();

    }
}
